<?php

/**
 * 基础订餐类
 * Created by PhpStorm.
 * User: allen_ios
 * Date: 17/6/12
 * Time: 下午11:08
 */
class BaseRestaurantService extends BaseService
{

    const REDIS_CACHE_EXPIRE = 600;
    private $CategoryModel;  // 分类模型
    private $restaurantId;     //餐厅id
    private $resId; // 模块id
    public function __construct()
    {

        $params = func_get_args();

        $this->resId = $params[0][0];
        $this->restaurantId = $params[0][1];
        $this->CategoryModel = D('Base/RestaurantGoodsCategory');
        $this->cacheKey =  'zdu_restaurant_category_'.$this->resId.'_'.$this->restaurantId;

    }

    /**
     * 根据模块id和餐厅id获取分类信息
     * @return mixed
     */
    public function getCategory()
    {

        /*//先取缓存，没有就取数据库再存入缓存expire = 600s;
        $cacheData = RedisService::get($this->cacheKey);
        if(!$cacheData){*/
            $condition = array(
                'res_id'=>$this->resId,
                'restaurant_id'=>$this->restaurantId,
                'cut_off'=>0
            );
            $field = 'category_id,category_name';
            $order = 'sort asc';
            $category = $this->CategoryModel->getList($condition,$field,$order);
            $mGoods = D('Base/RestaurantGoods');
            //找出各自分类下面的菜品
            foreach ($category as $k=>$v){
                $condition = array(
                    'res_id'=>$this->resId,
                    'restaurant_id'=>$this->restaurantId,
                    'category_id'=>$v['category_id'],
                    'cut_off'=>0,
                    'goods_sum'=>array('gt',0),
                    'show'=>1
                );
                $category[$k]['goods'] = $mGoods->where($condition)->field('goods_id,goods_name,price,goods_logo,goods_sum')->select();
            }
/*            if ($category) {
                //存入缓存
                $res = RedisService::set($this->cacheKey,json_encode($category),self::REDIS_CACHE_EXPIRE);
            }else{
                return null;
            }
            return $category;
        }*/
        return $category;

    }

    /**
     * 获得单个餐厅
     * @param int $resId    餐厅模块Id
     */
    protected function getRestaurantInfo($resId)
    {
        return array();
    }

    /**
     * 获得档口
     * @param int $resId 餐厅模块id
     * @param int $restaurantId 餐厅id
     */
    protected function getRestaurantWindows($resId,$restaurantId)
    {
        return array();
    }

    /**
     * 打印操作
     * @param $orderInfo
     */
    protected function doPrint($orderInfo)
    {

    }
}